package com.effective.java.inheritence;

import java.util.Collection;
import java.util.HashSet;

/**
 * This implementation relies on the implementation of its base class and is
 * therefore not working properly. This is an example of Fowler's principle of
 * the breakable base class.
 * 
 * @author andreas.landerer
 * 
 * @param <E>
 *            any type
 */
public class BrokenHashSetImpl<E> extends HashSet<E> {

	/**
	 * gererated serial version UUID
	 */
	private static final long serialVersionUID = 1126497793875704696L;

	/**
	 * the variable counts how many objects were added to the set.
	 */
	private int addCount = 0;

	/**
	 * {@inheritDoc}
	 */
	@Override
	public boolean add(E arg0) {

		this.addCount++;
		return super.add(arg0);
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public boolean addAll(Collection<? extends E> subset) {

		this.addCount += subset.size();
		return super.addAll(subset);
	}

	/**
	 * Get the value how many times an element was added to this set
	 * 
	 * @return the value how many times an element was added to this set
	 */
	public int getAddCount() {

		return this.addCount;
	}
}
